import java.util.Stack;

/**
 * @Author 12629
 * @Date 2022/3/19 11:08
 * @Description：
 */
public class MyQueueLeetCode {

    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public MyQueueLeetCode() {
        this.stack1 = new Stack<>();
        this.stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    /**
     * 弹出队头元素
     * @return
     */
    public int pop() {
        if(empty()) {
            return -1;//当前队列为空
        }
        if(stack2.empty()) {
            while (!stack1.empty()) {
                int val = stack1.pop();
                stack2.push(val);
            }
        }
        //第2个栈 不为空
        return stack2.pop();
    }

    /**
     * 获取队头元素
     * @return
     */
    public int peek() {
        if(empty()) {
            return -1;//当前队列为空
        }
        if(stack2.empty()) {
            while (!stack1.empty()) {
                int val = stack1.pop();
                stack2.push(val);
            }
        }
        //第2个栈 不为空
        return stack2.peek();
    }

    /**
     * 队列为空吗
     * @return
     */
    public boolean empty() {
        return stack1.empty() && stack2.empty();
    }
}
